<?php
/**
 *
 * Saadaan kalenterit listattua menuitemin luonnissa.
 * 
 */

defined('JPATH_BASE') or die;

jimport('joomla.html.html');
jimport('joomla.form.formfield');
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
require_once JPATH_ADMINISTRATOR.DS.'components'.DS.'com_eventcalendar'.DS.'helpers'.DS.'database.php';
/**
 * Form Field class for the Joomla Framework.
 *
 * @package		Joomla.Administrator
 * @subpackage	com_newsfeeds
 * @since		1.6
 */
 class JFormFieldKalenteri extends JFormFieldList
{
	/**
	 * The form field type.
	 *
	 * @var		string
	 * @since	1.6
	 */
	protected $type = 'Kalenteri';

	/**
	 * Method to get the field options.
	 *
	 * @return	array	The field option objects.
	 * @since	1.6
	 */
	protected function getOptions()
	{
		// Initialize variables.
		$options = array();
		
		//Connect to database
		$joku = new DatabaseHelper();
		$option = $joku->get('option');
		$db = & JDatabase::getInstance( $option );
		
		//$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);

		$query->select('id As value, nimi As text');
		$query->from('#__kalenteri AS a');
		$query->order('a.nimi');

		// Get the options.
		$db->setQuery($query);

		$options = $db->loadObjectList();

		// Check for a database error.
		if ($db->getErrorNum()) {
			JError::raiseWarning(500, $db->getErrorMsg());
		}

		// Merge any additional options in the XML definition.
		$options = array_merge(parent::getOptions(), $options);

		return $options;
	}
}
